//
//  stateCell.swift
//  kingWeiBo
//
//  Created by King on 15/9/16.
//  Copyright © 2015年 King. All rights reserved.
//

import UIKit

enum satusCellIdentifier: String{
    case  normolID = "normolID"
    case  forWordID = "forWordID"
    
    static func cellID(status: Status)->String{
        
        return status.retweeted_status == nil ? satusCellIdentifier.normolID.rawValue  :
                                                satusCellIdentifier.forWordID.rawValue
    
    }
    


}

class stateCell: UITableViewCell {

    
    
    
    var status:Status?{
        didSet{
           // print(status?.imageURL)
            topView.status = status
            textLable.text = status?.text
            picCV.status = status
            picHeightCons?.constant = picCV.bounds.size.height
            picWidthCons?.constant = picCV.bounds.size.width
            pictureTopCons?.constant = picCV.bounds.size.width == 0  ? 0 : 8
        }
        
    }
    
    var picHeightCons:NSLayoutConstraint?
    var picWidthCons:NSLayoutConstraint?
    /// 顶部约束
    var pictureTopCons: NSLayoutConstraint?

    //MARK: - 设置行高
    func rowHeight(statues:Status) -> CGFloat{
        self.status = statues
        if (status?.retweeted_status == nil)  {
           
        }
        layoutIfNeeded()
        let temp = CGRectGetMaxY(bottomview.frame)
        return  temp
    }
    
     func setUpUI(){
    
        contentView.addSubview(topView)
        contentView.addSubview(textLable)
        contentView.addSubview(bottomview)
        contentView.addSubview(picCV)
        
        topView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: CGSize(width: UIScreen.mainScreen().bounds.width, height:55))
        textLable.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topView, size: nil, offset: CGPoint(x: 8, y: 8))
        
        contentView.addConstraint(NSLayoutConstraint(item: textLable, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Width, multiplier: 1.0, constant: -20))
     
        bottomview.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: picCV, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 44), offset: CGPoint(x: -8, y: 8))
        
//        contentView.addConstraint(NSLayoutConstraint(item: bottomview, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0))
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setUpUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    //MARK: - 懒加载topview
    lazy var topView: TopView = TopView()
    //MARK: - 懒加载正文label
    lazy var textLable:UILabel = {
        
        let lab = UILabel(color: UIColor.blackColor(), fontSize: 14)
        lab.numberOfLines = 0

        return lab
    }()
    
    //MARK: - 懒加载配图View
    lazy  var  picCV:picCollectionView = picCollectionView()
    
    //MARK: - 懒加载bottomview
    lazy var bottomview: bottomView = bottomView()
    
    
    
    
    
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
